#define Antidewing_Variable

#include "userDef.h"

timer_antidewing_typeDef timer_antidewing;



void antidewingAct(void) // called in main()
{
    U16 tempi;

    static U16 tmp_roomTemp = 0;

    if (f_quickTest == 0 && f_SetNoCheckDewing == 0 && (e_mode.run == MODECOOL || e_mode.run == MODEDRY) && b_power.run == 1)
    {
        tempi = (U16)ver_Step.SwNow * 45 / 64;

        if (f_antidewing == 1)
        {
            if (timer_antidewing.on_min == 0)
            {
                if (temp.roomAct < (tmp_roomTemp + 10))
                {
                    timer_antidewing.temp_sec = 0;
                }
            }
            else
            {
                timer_antidewing.temp_sec = 0;
            }

            if (timer_antidewing.temp_sec >= 180 || temp.roomAct > 290 || temp.outdoor > (400 + 300))
            {
                f_antidewing = 0;

                timer_antidewing.off_min = 30;
                timer_antidewing.off_sec = 0;
            }

            if (e_verSw.set[e_mode.set] == 0x01 || tempi < 38 || (tempi > 53 && tempi < 73) || tempi > 88 || CompOnSumMin < 40)
            {
                f_antidewing = 0;

                timer_antidewing.off_min = 30;
                timer_antidewing.off_sec = 0;
            }
        }
        else
        {
            if (timer_antidewing.off_min == 0 && temp.roomAct <= 290 && temp.outdoor <= (400 + 300))
            {
                if (e_verSw.set[e_mode.set] != 0x01 && ((tempi >= 38 && tempi <= 53) || (tempi >= 73 && tempi <= 88)))
                {
                    if (CompOnSumMin >= 40)
                    {
                        f_antidewing = 1;
                        tmp_roomTemp = temp.roomAct;

                        timer_antidewing.on_min = 30;
                        timer_antidewing.on_sec = 0;
                    }
                }
            }
        }
    }
    else
    {
        f_antidewing = 0;
    }
}

void antidewingTime(void) // called in SysTime.c per 1s
{
    if (f_antidewing == 1)
    {
        timer_antidewing.off_sec = 0;
        timer_antidewing.off_min = 0;

        timer_antidewing.on_sec++;

        if (timer_antidewing.on_sec >= 60)
        {
            timer_antidewing.on_sec = 0;

            if (timer_antidewing.on_min > 0)
            {
                timer_antidewing.on_min--;
            }
        }

        if (timer_antidewing.temp_sec < 250)
        {
            timer_antidewing.temp_sec++;
        }
    }
    else
    {
        timer_antidewing.on_sec = 0;
        timer_antidewing.on_min = 0;

        timer_antidewing.temp_sec = 0;

        timer_antidewing.off_sec++;

        if (timer_antidewing.off_sec >= 60)
        {
            timer_antidewing.off_sec = 0;

            if (timer_antidewing.off_min > 0)
            {
                timer_antidewing.off_min--;
            }
        }
    }
}
